package com.demo1.factorys;

import com.demo1.entity.Person;
import com.demo1.test.Test;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

public class MyFactory {

     private static Map<String,Person> map=new HashMap<>();

    static {
        Properties properties = new Properties();
        InputStream inputStream = Test.class.getResourceAsStream("../test/person.properties");
        try{
            properties.load(inputStream);
            Set<String> keys = properties.stringPropertyNames();
            for (String name:keys) {
                String property = properties.getProperty(name);
                map.put(name,(Person)Class.forName(property).newInstance());

            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    public static   Person getF(String name){
        Person vlue=map.get(name);
        try{
            return (Person) Class.forName(String.valueOf(vlue)).newInstance();
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
}
